package code.mybatis.generator;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;

/**
* <p></p>
*
* @version 1.0
* @author:huangwf
* @date:2017/8/21 11:00
* @history
*/
public class GeneratorMain {
public static void main(String[] args) throws URISyntaxException {
List<String> warnings = new ArrayList<String>();
    boolean overwrite = true;
    //读取配置文件  file://D:/work/code/DongbaoSoft/dongbao-member/dongbao-member-web/src/test/resources/generator/generatorConfig.xml
    File configFile = new File(GeneratorMain.class.getResource("/generatorConfig.xml").toURI());
    ConfigurationParser cp = new ConfigurationParser(warnings);
    Configuration config;
    try {
    config = cp.parseConfiguration(configFile);

    DefaultShellCallback callback = new DefaultShellCallback(overwrite);
    MyBatisGenerator myBatisGenerator;
    try {
    myBatisGenerator = new MyBatisGenerator(config, callback,
    warnings);
    myBatisGenerator.generate(null);

    //打印结果
    for(String str : warnings){
    System.out.println(str);
    }
    } catch (Exception e) {
    e.printStackTrace();
    }

    } catch (IOException e) {
    e.printStackTrace();
    } catch (XMLParserException e) {
    e.printStackTrace();
    }
    }
    }